/**
 * 
 */
package br.com.ufrn.aipetro.ga.model.persist.hibernate;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import br.com.ufrn.aipetro.ga.controller.device.Teste;
import br.com.ufrn.aipetro.ga.domain.entity.device.Device;
import br.com.ufrn.aipetro.ga.domain.entity.device.maintenance.Maintenance;
import br.com.ufrn.aipetro.ga.model.persist.hibernate.util.HibernateUtil;
import br.com.ufrn.aipetro.ga.persist.interfaces.MaintenanceDao;

/**
 * 
 * @author Lucas
 *
 */
public class HibernateMaintenanceDao extends MaintenanceDao {
	
	Session session;
	Class entityClass;
	
	public HibernateMaintenanceDao(Class entityClass) {
		this.session = HibernateUtil.getSessionFactory().getCurrentSession();
		this.entityClass = entityClass;
		basicDao = new HibernateBasicDao<Maintenance>(session, entityClass);
	}

	@Override
	public List searchByDevice2(Date date1, Date date2) {
		List studentResult;
		return studentResult = session.createCriteria(Maintenance.class).
				add(Restrictions.between("dateStart", date1, date2)).list();			
	}

	@Override
	public List<Date> searchByDevice3(Device example) { //modificar select (mal feito)
		return session.createQuery("SELECT dateStart from Maintenance m where m.idTbDevice = :idTbDevice GROUP BY dateStart")
				.setEntity("idTbDevice", example)
				.list();
	}
	
	public List<Integer> searchByDevice4(Device example) { //modificar select (mal feito)
		return session.createQuery("SELECT COUNT(dateStart) from Maintenance m where m.idTbDevice = :idTbDevice GROUP BY dateStart")
				.setEntity("idTbDevice", example)
				.list();
	}
	
	
	
}
